package com.md.api.service.impl;

import com.md.api.common.utils.TokenUtil;
import com.md.api.dao.EvaluationRecordMapper;
import com.md.api.dao.PhoneCodeConfirmLawMapper;
import com.md.api.dao.PictureInfoMapper;
import com.md.api.entity.*;
import com.md.api.entity.dto.ComposeQueryDto;
import com.md.api.entity.util.Page;
import com.md.api.service.IndexSevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author liujie
 * @ClassName ProductServiceImpl
 **/

@Slf4j
@Service
public class IndexServiceImpl implements IndexSevice {


    @Resource
    PhoneCodeConfirmLawMapper confirmLawMapper;
    @Resource
    EvaluationRecordMapper recordMapper;
    @Resource
    PictureInfoMapper pictureInfoMapper;
    @Override
    public HttpResult evaluation(HttpServletRequest request, ComposeQueryDto qto) {
        Page page = qto.getPage();
        page.initPagingData(EvaluationRecord.class);
        List<EvaluationRecord> cartList = recordMapper.getEvaRecordRand(qto.getIsFineEvaluation());
        page.setResult(cartList);
        return new HttpResult(page);
    }


    @Override
    public HttpResult pictureShow(HttpServletRequest request, ComposeQueryDto qto) {
        Page page = qto.getPage();
        page.initPagingData(PictureInfo.class);
        List<PictureInfo> cartList = pictureInfoMapper.randPictureShow();
        page.setResult(cartList);
        return new HttpResult(page);
    }


    @Override
    public HttpResult picShow() {
        List<SysPcConfiguration> cartList = pictureInfoMapper.picShow();
        return new HttpResult(cartList);
    }

    @Override
    public HttpResult docInstruction(HttpServletRequest request,SysPcDocInstruction instruction) {
        String language = request.getHeader("language");
        List<SysPcDocInstruction> cartList = pictureInfoMapper.docInstruction(language,instruction.getCode());
        return new HttpResult(cartList);
    }


    @Override
    public HttpResult phoneCode(ComposeQueryDto queryDto) {
        Page page = queryDto.getPage();
        page.initPagingData(PhoneCodeConfirmLaw.class);
        List<PhoneCodeConfirmLaw> cartList = confirmLawMapper.list();
        page.setResult(cartList);
        return new HttpResult(page);
    }

    @Override
    public HttpResult law(PhoneCodeConfirmLaw codeConfirmLaw) {
        PhoneCodeConfirmLaw law= confirmLawMapper.getByPhoneCode(codeConfirmLaw.getPhoneCode());
        return new HttpResult(law);
    }
}